package com.novax.ex.activity.provider.controller.inner;

import com.novax.ex.activity.infrastructure.entity.RankSubConfig;
import com.novax.ex.activity.open.api.inner.RankSubConfigApi;
import com.novax.ex.activity.open.model.response.RankSubConfigResponse;
import com.novax.ex.activity.provider.controller.BaseActivityController;
import com.novax.ex.activity.provider.service.RankSubConfigService;
import com.novax.ex.common.constant.InternationalCode;
import com.novax.ex.common.results.ReturnResult;
import com.novax.ex.common.util.CopyUtils;
import org.springframework.web.bind.annotation.RestController;

import jakarta.annotation.Resource;
import java.util.List;

@RestController
public class RankSubConfigController extends BaseActivityController implements RankSubConfigApi {

    @Resource
    private RankSubConfigService rankSubConfigService;

    @Override
    public ReturnResult<List<RankSubConfigResponse>> subList(Long rankId) {
        return ReturnResult.success(CopyUtils.copyList(rankSubConfigService.subList(rankId, null), RankSubConfigResponse.class));
    }

    @Override
    public ReturnResult<?> modify(String language, Long rankSubId, Integer number) {
        if (number < 0) {
            return  ReturnResult.fail(getInternational(language, InternationalCode.VALUE_GREATER_ZERO));
        }
        RankSubConfig rankSubConfig = new RankSubConfig();
        rankSubConfig.setId(rankSubId);
        rankSubConfig.setNumber(number);
        boolean flag = rankSubConfigService.modifySelective(rankSubConfig);
        return flag ? ReturnResult.success(getInternational(language, InternationalCode.OPERATION_SUCCESS)) :
            ReturnResult.fail(getInternational(language, InternationalCode.OPERATION_ERROR));
    }

}
